<template>
  <div class="demo">
    <h2 class="name">学生姓名：{{ name }}</h2>
    <h2>学生性别：{{ sex }}</h2>
    <button @click="sendStudentName">发送学生姓名</button>
    <button @click="unbind">解绑事件</button>
    <button @click="death">销毁当前组件实例</button>
  </div>
</template>

<script>
export default {
  name: "Student",
  data() {
    return {
      name: "张三123456",
      sex: "男",
    };
  },
  methods: {
    sendStudentName() {
      this.$emit("getStudentName", this.name);
      this.$emit("demo");
    },
    unbind() {
      // this.$off("getStudentName"); // 解绑单个事件
      this.$off(["getStudentName", "demo"]); // 解绑多个事件
      // this.$off() // 解绑所有事件
    },
    death() {
      console.log("组件实例即将销毁");
      this.$destroy();
    },
  },
};
</script>

<style scoped lang="less">
.demo {
  background-color: plum;
  color: white;
  .name {
    font-size: 50px;
    color: palegreen;
  }
}
</style>
